package com.jc.demo.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

@SuppressWarnings("Duplicates")
public class UpdateDataDemo {


    public static void main(String[] args) throws IOException {
        // Instantiating Configuration class
        Configuration config = HBaseConfiguration.create();

        // Instantiating HTable class
        Connection connection = ConnectionFactory.createConnection(config);
        Table hTable = connection.getTable(TableName.valueOf("emp"));
        try {

            // Instantiating Put class
            // accepts a row name.
            Put p = new Put(Bytes.toBytes("row1"));

            // adding values using add() method
            // accepts column family name, qualifier/row name ,value
            p.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("name"), Bytes.toBytes("raju3"));

            p.addColumn(Bytes.toBytes("personal"),
                    Bytes.toBytes("city"), Bytes.toBytes("hyderabad3"));

            p.addColumn(Bytes.toBytes("professional"), Bytes.toBytes("designation"),
                    Bytes.toBytes("manager3"));

            p.addColumn(Bytes.toBytes("professional"), Bytes.toBytes("salary"),
                    Bytes.toBytes("50003"));

            // Saving the put Instance to the HTable.
            hTable.put(p);
            System.out.println("data updated");

        } finally {
            hTable.close();
            connection.close();
        }

    }
}
